﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcReplace.CCoTcReplacePrototypeCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using COMMANDPARAMSLib;
using EngineeringInternalExtension;
using EngineeringInternalExtension.Utilities;
using System;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.TcCommands.TcReplace;

public class CCoTcReplacePrototypeCmd : CCoTcReplaceBaseCmd
{
  private CUiReplaceDialog dialog;

  public CCoTcReplacePrototypeCmd()
  {
    this.m_dialogIsOpen = false;
    this.m_cmdEnabler = new CCoTcReplaceCmdBaseEnabler();
  }

  public virtual string Description => DnProcessSimulateCommands.StringTable.REPLACE_PROTOTYPE_CMD_DESCRIPTION;

  public virtual string Name => DnProcessSimulateCommands.StringTable.REPLACE_PROTOTYPE_CMD_NAME;

  public virtual string Tooltip => DnProcessSimulateCommands.StringTable.REPLACE_PROTOTYPE_CMD_TOOLTIP;

  public virtual void Execute(object cmdParams)
  {
    if (this.m_dialogIsOpen)
      return;
    if (TxTcSessionInfoEx.CheckViewsAvailability())
    {
      if (TxEngineeringDataInternal.GlobalSessionIsDatabaseModified() && TxMessageBox.Show(DnProcessSimulateCommands.StringTable.REPLACE_PROTOTYPE_SAVE_TEXT, base.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      {
        TxCommandManager txCommandManager = new TxCommandManager();
        CoExportToTcParams exportToTcParams = (CoExportToTcParams) new CoExportToTcParamsClass();
        ((ICoExportToTCParams) exportToTcParams).SetConfirmSave(0);
        txCommandManager.ExecuteCommandByCommandProgId("TCIntegCommands.CCoExportToTC", (object) exportToTcParams, false);
      }
      this.dialog = new CUiReplaceDialog((CCoTcReplaceBaseCmd) this);
      ((FrameworkElement) this.dialog).Loaded += new RoutedEventHandler(this.Dialog_Loaded);
      ((Window) this.dialog).Closed += new EventHandler(this.Dialog_Closed);
      ((Window) this.dialog).Show();
    }
    else
      TxErrorStackDlg.DisplayErrors();
  }

  private void Dialog_Loaded(object sender, RoutedEventArgs e)
  {
  }

  private void Dialog_Closed(object sender, EventArgs e)
  {
    ((FrameworkElement) this.dialog).Loaded -= new RoutedEventHandler(this.Dialog_Loaded);
    ((Window) this.dialog).Closed -= new EventHandler(this.Dialog_Closed);
    if (!this.dialog.Result || TxMessageBox.Show(DnProcessSimulateCommands.StringTable.REPLACE_PROTOTYPE_RELOAD_TEXT, base.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
      return;
    System.Windows.Input.Cursor overrideCursor = Mouse.OverrideCursor;
    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
    Mouse.UpdateCursor();
    try
    {
      new TxDocumentEx().ReloadCurrentStudyFromTc();
    }
    finally
    {
      Mouse.OverrideCursor = overrideCursor;
      Mouse.UpdateCursor();
    }
  }

  public virtual string Bitmap => "TcCommands.TcReplace.Images.ReplaceResourceRroto.bmp";

  public virtual string LargeBitmap => "TcCommands.TcReplace.Images.ReplaceResourceRrotoBig.png";

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("ReplaceResourceTc");
}
